/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.cpimex.eprice.action;

import com.cpimex.eprice.forms.DetalleGerenteRegionalForm;
import com.cpimex.eprice.model.GerenteRegional;
import com.cpimex.eprice.model.Logistica;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

/**
 * Level 5 la clase completa es nueva
*/
public class DetalleGerenteregionalAction extends DispatchAction{

     public ActionForward listarGerentesRegional( ActionMapping mapping, 
             ActionForm form, HttpServletRequest request,
             HttpServletResponse response )throws Exception {

         DetalleGerenteRegionalForm formAction=(DetalleGerenteRegionalForm)form;
         
         GerenteRegional gerente =GerenteRegional
                 .getGerenteRegionalPorID(formAction.getNumeroGerente()); // Level 5 ***
         
         if (gerente!=null){
             formAction.setNombreGerente(gerente.getNombre());
             formAction.setCodigoRegion(gerente.getCodigoRegion());
             formAction.setDescripcionRegion(gerente.getRegionDesc());
             formAction.setNumeroGerente(gerente.getNumeroGerente()); 
             
             formAction.setNumeroGerenteSel(gerente.getNumeroGerente());
             
             System.out.println("Id Gerencia " + gerente.getNumeroGerente()); //level 5
             
             formAction.setIdGerente(gerente.getIdGerente());
             // level 5 ***
             
             request.setAttribute("gerentes", GerenteRegional.getEmpleadosPerfilGerenteRegional());
         }

                  
         return mapping.findForward("listadoGerente");
     } 
     
     public ActionForward EditarGerentesRegional( ActionMapping mapping, 
             ActionForm form, HttpServletRequest request,
             HttpServletResponse response )throws Exception {

         DetalleGerenteRegionalForm formAction=(DetalleGerenteRegionalForm)form;

         GerenteRegional.actualizarGerentes(formAction.getNumeroGerente(),
                formAction.getCodigoRegion(),formAction.getDescripcionRegion(),
                formAction.getIdGerente());
         
         request.setAttribute("gerentes", GerenteRegional.getEmpleadosPerfilGerenteRegional()); //level 5 ***
                  
         return mapping.findForward("listadoGerente");
     }    
     
     public ActionForward cancel( ActionMapping mapping, 
             ActionForm form, HttpServletRequest request,
             HttpServletResponse response )throws Exception {

         DetalleGerenteRegionalForm formAction=(DetalleGerenteRegionalForm)form;
                  
         return mapping.findForward("maestro");
     }     
    
}
